package com.sixfoot.domain;

import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.OrderBy;
import javax.persistence.Table;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.sixfoot.domain.scale.Scale;
import com.sixfoot.foundation.persistence.IdentityBaseModel;
import com.sixfoot.foundation.persistence.UUIDBaseModel;

@Entity
@Table(name = "resource")
public class Resource extends IdentityBaseModel {

	private String name;		// 菜单名称
//	private String url;			// 菜单URL
//	private String tab;			// 用于获取菜单的标记
	private Resource parent;		// 父菜单
	@JsonIgnore
	private Set<Resource> childs;	// 子菜单
	private int seq;			// 用于菜单排序
	private Set<Scale> scales;		// 记录
	private Permission permission;	// 权限
	private ResourceType type = ResourceType.menu; 	// 资源类型
	private String parentIds;
	
	public static enum ResourceType {
		menu("菜单"), button("按钮");

		private final String info;

		private ResourceType(String info) {
			this.info = info;
		}

		public String getInfo() {
			return info;
		}
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

//	public String getUrl() {
//		return url;
//	}
//
//	public void setUrl(String url) {
//		this.url = url;
//	}

	@ManyToOne
	public Resource getParent() {
		return parent;
	}

	public void setParent(Resource parent) {
		this.parent = parent;
	}

	@OneToMany(mappedBy = "parent")
	@OrderBy("seq")
	public Set<Resource> getChilds() {
		return childs;
	}

	public void setChilds(Set<Resource> childs) {
		this.childs = childs;
	}

//	public String getTab() {
//		return tab;
//	}
//
//	public void setTab(String tab) {
//		this.tab = tab;
//	}

	public int getSeq() {
		return seq;
	}

	public void setSeq(int seq) {
		this.seq = seq;
	}

//	public String getStyle() {
//		return style;
//	}
//
//	public void setStyle(String style) {
//		this.style = style;
//	}
	@Enumerated(EnumType.STRING)
	@Column(length = 5, nullable = false)
	public ResourceType getType() {
		return type;
	}

	public void setType(ResourceType type) {
		this.type = type;
	}
	
	@OneToMany(mappedBy = "resource")
	public Set<Scale> getScales() {
		return scales;
	}

	public void setScales(Set<Scale> scales) {
		this.scales = scales;
	}

	@OneToOne
	public Permission getPermission() {
		return permission;
	}

	public void setPermission(Permission permission) {
		this.permission = permission;
	}

	@Override
	public String toString() {
		return "Resource [name=" + name + ", childs=" + childs + ", seq=" + seq + ", type=" + type + "]";
	}

	public String getParentIds() {
		return parentIds;
	}

	public void setParentIds(String parentIds) {
		this.parentIds = parentIds;
	}

	
}
